
using Youz.Common.DAL;
using Youz.Common.Entity;
using Youz.Common.Helper;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

namespace Youz.Common.BLL
{
    /// <summary>
    /// Sys_Currency BLL Class
    /// </summary>
    public partial class Sys_CurrencyBLL : BaseBLL
    {
        Sys_CurrencyDAL dal;
        
        public Sys_CurrencyBLL()
        {
            dal = new Sys_CurrencyDAL();
            base.ModuleName = "Sys_Currency";
            base.MenuName = "Sys_Currency";
        }

        #region  成员方法
        /// <summary>
        ///  新增一条数据
        /// </summary>
        public bool Add(Sys_Currency model)
        {
            model.Creator = Utility.MemberAccount;
            model.CreateTime = DateTime.Now;
            model.LastModifier = model.Creator;
            model.LastModifyTime = DateTime.Now;

            var r = dal.Add(model);
            
            base.WriteOperationLog(OperationType.Add, r, Utility.GetJsonByObjectHaveTime(model));

            return r;
        }

        /// <summary>
        ///  保存一条数据
        /// </summary>
        public bool Update(Sys_Currency model)
        {
            model.LastModifier = model.Creator;
            model.LastModifyTime = DateTime.Now;

            var r = dal.Update(model);

            base.WriteOperationLog(OperationType.Update, r, Utility.GetJsonByObjectHaveTime(model));

            return r;
        }

        /// <summary>
        /// 删除一条数据
        ///</summary>
        public bool Delete(String CurrencyID)
        {
            var r = dal.Delete(CurrencyID);
            
            base.WriteOperationLog(OperationType.Delete, r, CurrencyID);

            return r;
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Sys_Currency Get(String CurrencyID)
        {
            return dal.Get(CurrencyID);
        }
        
        /// <summary>
        /// 得到一个JSON对象
        /// </summary>
        public string GetJson(String CurrencyID)
        {
            return Utility.GetJsonByObject(Get(CurrencyID));
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet Gets(string sqlWhere)
        {
            return dal.Gets(sqlWhere);
        }
        
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet Gets(int top, string sqlWhere, string filedOrder)
        {
            return dal.Gets(top, sqlWhere, filedOrder);
        }
        
        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string sqlWhere)
        {
            return dal.GetRecordCount(sqlWhere);
        }
        
        /// <summary>
        /// 获得数据列表分页
        /// </summary>
        public DataTable Gets(string sqlWhere, int pageindex, int pagesize, out int total, params SqlParameter[] cmdParms)
        {
            return dal.Gets(sqlWhere, pageindex, pagesize, out total, cmdParms);
        }
        #endregion  成员方法

        /// <summary>
        /// 获取公司收款账户
        /// </summary>
        /// <returns></returns>
        public List<Sys_Currency> GetCurrency()
        {
            List<Sys_Currency> list;
            string json = Utility.GetJsonByObject(dal.GetCurrency());
            list = JsonConvert.DeserializeObject<List<Sys_Currency>>(json);
            return list;
        }

        /// <summary>
        /// 获得汇率
        /// </summary>
        /// <param name="currency"></param>
        /// <returns></returns>
        public Decimal GetRate(String currency)
        {
            var model = Get(currency);
            return model == null ? 0 : model.Rate;
        }
    }
}


  